package cn.siat.gene.controller;

import cn.siat.common.core.web.controller.BaseController;
import cn.siat.common.core.web.domain.AjaxResult;
import cn.siat.common.core.web.page.TableDataInfo;
import cn.siat.common.log.annotation.Log;
import cn.siat.common.log.enums.BusinessType;
import cn.siat.gene.domain.GenomeData;
import cn.siat.gene.domain.ProgrammeFlieMinio;
import cn.siat.gene.domain.dto.GenomeDataDto;
import cn.siat.gene.domain.dto.GenomeDataQueryParam;
import cn.siat.gene.domain.vo.GenomeDataVO;
import cn.siat.gene.service.*;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.*;

/**
 * @Description: 基因组数据信息
 * @Author: mingwei
 * @Date: 2023-7-23
 * @Version: V1.0
 */
@Api(tags = "基因组数据信息")
@RestController
@RequestMapping("/genomeData")
@Slf4j
public class GenomeDataController extends BaseController {
    @Autowired
    private IGenomeDataService genomeDataService;
    @Autowired
    private IProgrammeFlieMinioService programmeFlieMinioService;
    /**
     * 分页列表查询
     *
     * @return
     */
    @Log(title = "基因组数据查询", businessType = BusinessType.VIEWED)
    @ApiOperation(value = "基因组数据查询", notes = "基因组数据查询")
    @GetMapping(value = "/list")
    public TableDataInfo queryPageList(GenomeDataQueryParam queryParams) {
        startPage();
        List<GenomeDataVO> pageList = genomeDataService.queryPageList(queryParams);
        return getDataTable(pageList);
    }

    @ApiOperation(value = "基因组数据文件列表查询", notes = "基因组数据文件列表查询")
    @GetMapping(value = "/fileList")
    public TableDataInfo queryFlieList(String id) {
        List<ProgrammeFlieMinio> pageList = programmeFlieMinioService.queryFileListById(id);
        return getDataTable(pageList);
    }
    /**
     * 删除基因组数据
     */
    @Log(title = "基因组数据", businessType = BusinessType.DELETE)
    @DeleteMapping("/remove")
    public AjaxResult removeGenomeData(@RequestBody GenomeData genomeData)
    {
        return toAjax(genomeDataService.deleteGenomeDataById(genomeData));
    }
    /**
     * 新增基因组数据
     */
    @Log(title = "基因组数据", businessType = BusinessType.INSERT)
    @PostMapping("/save")
    public AjaxResult saveGenomeData(@RequestBody GenomeDataDto genomeDataDto)
    {
        return AjaxResult.success(genomeDataService.insertGenomeDataDto(genomeDataDto));
    }
    /**
     * 修改基因组数据
     */
    @Log(title = "基因组数据", businessType = BusinessType.INSERT)
    @PostMapping("/update")
    public AjaxResult updateGenomeData(@RequestBody GenomeDataDto genomeDataDto)
    {
        return toAjax(genomeDataService.updateGenomeData(genomeDataDto));
    }
    /**
     * 修改基因组数据状态
     */
    @Log(title = "基因组数据", businessType = BusinessType.INSERT)
    @PostMapping("/updateStatus")
    public AjaxResult updateGenomeDataStatus(@RequestBody Map<String,String> map)
    {
        return toAjax(genomeDataService.updateGenomeDataStatus(map));
    }

    /**
     * 校验名称(已存在返回true)
     * @param name
     * @return
     */
    @GetMapping("/checkName")
    public AjaxResult checkName(String name,String id){
        Boolean isExist = genomeDataService.checkName(name,id);
        return AjaxResult.success(isExist);
    }

    /**
     * 根据minio_file md5查询minio文件id
     *
     * @return
     */
    @ApiOperation(value = "根据minio_file md5查询minio文件id", notes = "根据minio_file md5查询minio文件id")
    @GetMapping(value = "/getMinioFileIds")
    public AjaxResult queryMinioFileIds(String minioFileMd5Str) {
        Long[] ids = genomeDataService.queryMinioFileIds(minioFileMd5Str);
        return AjaxResult.success(ids);
    }
}
